package com.wilmer.userSchedule.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.wilmer.userSchedule.domain.vo.editVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wilmer.common.annotation.Log;
import com.wilmer.common.core.controller.BaseController;
import com.wilmer.common.core.domain.AjaxResult;
import com.wilmer.common.enums.BusinessType;
import com.wilmer.userSchedule.domain.SysUserSchedule;
import com.wilmer.userSchedule.service.ISysUserScheduleService;
import com.wilmer.common.utils.poi.ExcelUtil;
import com.wilmer.common.core.page.TableDataInfo;

/**
 * 用户日程Controller
 *
 * @author hans
 * @date 2024-04-11
 */
@Api(tags = {"用户日程接口"})
@RestController
@RequestMapping("/userSchedule/schedule")
public class SysUserScheduleController extends BaseController
{

    @Autowired
    private ISysUserScheduleService sysUserScheduleService;

    /**
     * 查询用户日程列表
     */
    @ApiOperation("查询用户日程列表")
    @PreAuthorize("@ss.hasPermi('userSchedule:schedule:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysUserSchedule sysUserSchedule)
    {
        startPage();
        List<SysUserSchedule> list = sysUserScheduleService.selectSysUserScheduleList(sysUserSchedule);
        return getDataTable(list);
    }

    @ApiOperation("")
    @PreAuthorize("@ss.hasPermi('userSchedule:schedule:list')")
    @GetMapping("/listUser")
    public TableDataInfo listUser(SysUserSchedule sysUserSchedule)
    {
        startPage();
        List<SysUserSchedule> list = sysUserScheduleService.selectScheduleList(sysUserSchedule);
        return getDataTable(list);
    }

    /**
     * 导出用户日程列表
     */
    @ApiOperation("导出用户日程列表")
    @PreAuthorize("@ss.hasPermi('userSchedule:schedule:export')")
    @Log(title = "用户日程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysUserSchedule sysUserSchedule)
    {
        List<SysUserSchedule> list = sysUserScheduleService.selectSysUserScheduleList(sysUserSchedule);
        ExcelUtil<SysUserSchedule> util = new ExcelUtil<SysUserSchedule>(SysUserSchedule.class);
        util.exportExcel(response, list, "用户日程数据");
    }
    /**
     * 获取用户日程详细信息
     */
    @ApiOperation("获取用户日程详细信息")
    @PreAuthorize("@ss.hasPermi('userSchedule:schedule:query')")
    @GetMapping(value = "/{scheduleId}")
    public AjaxResult getInfo(@PathVariable("scheduleId") Long scheduleId)
    {
        return success(sysUserScheduleService.selectSysUserScheduleByScheduleId(scheduleId));
    }

    /**
     * 新增用户日程
     */
    @ApiOperation("新增用户日程")
    @PreAuthorize("@ss.hasPermi('userSchedule:schedule:add')")
    @Log(title = "用户日程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysUserSchedule sysUserSchedule)
    {
        return toAjax(sysUserScheduleService.insertSysUserSchedule(sysUserSchedule));
    }
    /**
     * 修改用户日程
     */
    @ApiOperation("修改用户日程")
    @PreAuthorize("@ss.hasPermi('userSchedule:schedule:edit')")
    @Log(title = "用户日程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysUserSchedule sysUserSchedule)
    {
        return toAjax(sysUserScheduleService.updateSysUserSchedule(sysUserSchedule));
    }

    @ApiOperation("")
    @PreAuthorize("@ss.hasPermi('userSchedule:schedule:edit')")
    @Log(title = "用户日程", businessType = BusinessType.UPDATE)
    @PutMapping("/doEdit")
    public AjaxResult doEdit(@RequestBody editVo editVo)
    {
        return toAjax(sysUserScheduleService.doEdit(editVo));
    }
    /**
     * 删除用户日程
     */
    @ApiOperation("删除用户日程")
    @PreAuthorize("@ss.hasPermi('userSchedule:schedule:remove')")
    @Log(title = "用户日程", businessType = BusinessType.DELETE)
	@DeleteMapping("/{scheduleIds}")
    public AjaxResult remove(@PathVariable Long[] scheduleIds)
    {
        return toAjax(sysUserScheduleService.deleteSysUserScheduleByScheduleIds(scheduleIds));
    }
}
